package com.mi.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mi.entity.*;
import com.mi.service.Service_PointService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ServiceSupportController {

    @Reference(check = false)
    Service_PointService service_pointService;

    //查询维修服务
    @RequestMapping("repairList")
    public String repairList(HttpServletRequest request, RepairEntity repairEntity){
        MyPages<RepairEntity> repairEntityMyPages = service_pointService.queryRepairs(repairEntity);
        request.setAttribute("pageInfo",repairEntityMyPages);
        request.setAttribute("linkName",repairEntity.getLinkName());
        return "repairList";
    }

    //删除维修服务
    @RequestMapping("delRepair")
    @ResponseBody
    public ResponseMsg delRepair(String ids){
        ResponseMsg rm = new ResponseMsg();
        String[] r_ids;
        if (ids.contains(",")) {
            r_ids = ids.split(",");
        } else {
            r_ids = new String[]{ids};
        }
        boolean b = service_pointService.delRepair(r_ids);
        if (b) {
            rm.setResult("0000");
        } else {
            rm.setResult("0001");
            rm.setResultMsg("删除失败");
        }
        return rm;
    }

    //查询维修服务
    @RequestMapping("dataRequestList")
    public String dataRequestList(HttpServletRequest request, DataRequestEntity dataRequestEntity){
        MyPages<DataRequestEntity> dataRequestEntityMyPages = service_pointService.queryDataRequests(dataRequestEntity);
        request.setAttribute("pageInfo",dataRequestEntityMyPages);
        request.setAttribute("linkName",dataRequestEntity.getLinkName());
        return "dataRequestList";
    }

    //删除维修服务
    @RequestMapping("delDataRequest")
    @ResponseBody
    public ResponseMsg delDataReques(String ids){
        ResponseMsg rm = new ResponseMsg();
        String[] d_ids;
        if (ids.contains(",")) {
            d_ids = ids.split(",");
        } else {
            d_ids = new String[]{ids};
        }
        boolean b = service_pointService.delDataRequest(d_ids);
        if (b) {
            rm.setResult("0000");
        } else {
            rm.setResult("0001");
            rm.setResultMsg("删除失败");
        }
        return rm;
    }

    //查询投诉建议
    @RequestMapping("complaintSuggestList")
    public String complaintSuggestList(HttpServletRequest request, ComplaintSuggestEntity complaintSuggestEntity){
        MyPages<ComplaintSuggestEntity> complaintSuggestEntityMyPages = service_pointService.queryComplaintSuggests(complaintSuggestEntity);
        request.setAttribute("pageInfo",complaintSuggestEntityMyPages);
        request.setAttribute("linkName",complaintSuggestEntity.getLinkName());
        return "complaintSuggestList";
    }

    //删除投诉建议
    @RequestMapping("delComplaintSuggest")
    @ResponseBody
    public ResponseMsg delComplaintSuggest(String ids){
        ResponseMsg rm = new ResponseMsg();
        String[] c_ids;
        if (ids.contains(",")) {
            c_ids = ids.split(",");
        } else {
            c_ids = new String[]{ids};
        }
        boolean b = service_pointService.delComplaintSuggest(c_ids);
        if (b) {
            rm.setResult("0000");
        } else {
            rm.setResult("0001");
            rm.setResultMsg("删除失败");
        }
        return rm;
    }
}
